from flask import Flask
from models import db
from flask_cors import CORS
from views.user import user_bp
from views.oauth_user import oauth_user_bp
from views.courses import courses_bp
from views.comment import comment_bp
from common.utlis.jwt_auth import jwt_authentication
from views.vip import vip_bp
from views.pay import pay_bp
from views.pathes import path_bp


def create_flask_app(config):
    app = Flask(__name__)
    # 从配置文件中加载
    app.config.from_object(config)
    # 配置跨域
    cors = CORS(app)
    # 初始化
    db.init_app(app)

    # 请求钩子函数
    app.before_request(jwt_authentication)
    # 注册蓝图
    app.register_blueprint(user_bp)
    app.register_blueprint(oauth_user_bp)
    app.register_blueprint(courses_bp)
    app.register_blueprint(comment_bp)
    app.register_blueprint(vip_bp)
    app.register_blueprint(pay_bp)
    app.register_blueprint(path_bp)


    return app